package tech.aistar.corejava.day12.homework.home05;

import java.util.*;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
 * @CreateDate: 2019/7/31
 * @Version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        Product p1 = new Product(1,"洗手粉1",218.5,"中国");
        Product p2 = new Product(2,"洗手粉2",118.5,"中国");
        Product p3 = new Product(3,"洗手粉3",318.5,"中国");
        Product p4 = new Product(1,"洗手粉1",218.5,"中国");
        Product p5 = new Product(4,"洗手粉4",418.5,"中国");

        TreeSet<Product> treeSet = new TreeSet<>(new Comparator<Product>() {
            @Override
            public int compare(Product o1, Product o2) {
                //需要对价格进行降序
                if(o1.getPrice() < o2.getPrice())
                    return -1;
                else if(o1.getPrice() > o2.getPrice())
                    return 1;
                return 0;
            }
        });

        treeSet.add(p1);
        treeSet.add(p2);
        treeSet.add(p3);
        treeSet.add(p4);
        treeSet.add(p5);


        Iterator<Product> iter = treeSet.iterator();
        while(iter.hasNext()){
            System.out.println(iter.next());
        }



    }

}
